#!/usr/bin/python

# ---------------------------------------------------------------------	#
# mcast-send	- Send command to multicast group.			#
#									#
# version 0.1	- cj (2010-08-20) init.					#
# ---------------------------------------------------------------------	#

import os
import sys
import socket 
import struct
import subprocess

PASSPHRASE="passphrase.txt"

MCAST_PORT = 55555
MCAST_GRP  = '224.1.1.1'

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
s.connect((MCAST_GRP, MCAST_PORT))

# Decode command string that receive from multicast channel
# or else return NULL string as unrecognize command
def	decode():
	return
	
print "Ready..."
while True:
	data = raw_input("send : ")
	s.send(data)
	print "data = %s " % data

exit(0)

cmd1 = [ "/bin/cat", "input.txt" ]
cmd2 = [ "/usr/bin/aespipe", "-P", PASSPHRASE ]
	
# multicast socket

def mcastSock(addr, port):
	"""Multicast Socket Create"""
	"""Nothing here yet!"""
	exit(0)

def encryptCommand(str):
	"""Encrypted command string using gpg"""
	exit(0)

p1 = subprocess.Popen(cmd1, stdout=subprocess.PIPE)
p2 = subprocess.Popen(cmd2, stdin=p1.stdout, stdout=subprocess.PIPE)
output = p2.communicate()[0]

print output

exit(0)
# loop while receive command line
while True :
	try:
		line = raw_input(": ")
	except	EOFError:
		print "Got Control-D, Goodbye!"
		exit(0)

	if line == "quit" :
		exit(0)

	print "input = '"+line+"'"

# ---------------------------------------------------------------------	#
# end of file.								#
# ---------------------------------------------------------------------	#
